/**
 * Jaxson ajax
 *
 * Copyright Remedy Interactive, licensed under Apache version 2 license:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0.html
 *
 * This notice must remain in all java source files.
 */
package org.jaxson.struts.charts.pie;

import java.awt.Color;
import java.text.AttributedString;
import java.util.HashMap;
import java.util.Map;

import org.jaxson.struts.charts.ChartFormat;
import org.jfree.chart.labels.PieSectionLabelGenerator;
import org.jfree.chart.labels.PieToolTipGenerator;
import org.jfree.chart.labels.StandardPieToolTipGenerator;
import org.jfree.chart.urls.PieURLGenerator;
import org.jfree.data.general.PieDataset;

/**
 * Formatting specific to a Pie Chart.
 * 
 * @author Joe Maisel
 *
 */
public class PieChartFormat extends ChartFormat
{
	private boolean is3D = true;
	private Map<String, Color> paint = new HashMap<String, Color>();
	private Map<Comparable<? extends Object>, String> clickUrls = new HashMap<Comparable<? extends Object>, String>();
	private PieToolTipGenerator toolTipGenerator = new StandardPieToolTipGenerator();
	
	private PieSectionLabelGenerator labelGenerator = new PieSectionLabelGenerator()
	{
		@Override
		@SuppressWarnings("unchecked")
		public AttributedString generateAttributedSectionLabel( PieDataset pd, Comparable key )
		{
			return pd.getValue( key ) == null?null:new AttributedString( pd.getValue( key ) + "" );
		}

		@Override
		@SuppressWarnings("unchecked")
		public String generateSectionLabel( PieDataset pd, Comparable key )
		{
			return pd.getValue( key ) == null?null:pd.getValue( key ) + "";
		}
	};
	
	private PieURLGenerator urlGenerator = new PieURLGenerator()
	{
		@Override
		@SuppressWarnings("unchecked")
		public String generateURL( PieDataset pd, Comparable key, int idx )
		{
			return getClickUrl( key ) ;
		}
	};
	
	/**
	 * @return the is3D
	 */
	public boolean is3D()
	{
		return is3D;
	}
	/**
	 * @param is3D the is3D to set
	 */
	public void setIs3D( boolean is3D )
	{
		this.is3D = is3D;
	}
	/**
	 * Set the URL for a clickable region on the graph.  The URL will be part
	 * of the image map associated with the chart.
	 * 
	 * @param key
	 * @param value
	 */
	public void setClickUrl( Comparable<? extends Object> key, String value )
	{
		clickUrls.put( key, value );
	}
	/**
	 * Get the URL for a clickable region on the graph.  The URL will be part
	 * of the image map associated with the chart.
	 */
	public String getClickUrl( Comparable<? extends Object> key )
	{
		return clickUrls.get( key );
	}
	/**
	 * Set the color for a segment of the chart.
	 * 
	 * @param name
	 * @param color
	 */
	public void setSectionPaint( String name, Color color )
	{
		paint.put( name, color );
	}
	/**
	 * @return the paint
	 */
	public Map<String, Color> getPaint()
	{
		return paint;
	}
	/**
	 * @param paint the paint to set
	 */
	public void setPaint( Map<String, Color> paint )
	{
		this.paint = paint;
	}
	/**
	 * @return the labelGenerator
	 */
	public PieSectionLabelGenerator getLabelGenerator()
	{
		return labelGenerator;
	}
	/**
	 * @param labelGenerator the labelGenerator to set
	 */
	public void setLabelGenerator( PieSectionLabelGenerator labelGenerator )
	{
		this.labelGenerator = labelGenerator;
	}
	/**
	 * @return the urlGenerator
	 */
	public PieURLGenerator getUrlGenerator()
	{
		return urlGenerator;
	}
	/**
	 * @param urlGenerator the urlGenerator to set
	 */
	public void setUrlGenerator( PieURLGenerator urlGenerator )
	{
		this.urlGenerator = urlGenerator;
	}
	/**
	 * @return the toolTipGenerator
	 */
	public PieToolTipGenerator getToolTipGenerator()
	{
		return toolTipGenerator;
	}
	/**
	 * @param toolTipGenerator the toolTipGenerator to set
	 */
	public void setToolTipGenerator( PieToolTipGenerator toolTipGenerator )
	{
		this.toolTipGenerator = toolTipGenerator;
	}
}
